package log

import (
	"fmt"
	"io"
	stdLog "log"
	"os"
)

type Logger struct {
	logger *stdLog.Logger
	wc     io.WriteCloser
}

func NewLogger() *Logger {
	return &Logger{stdLog.New(os.Stderr, "", 0), nil}
}
func (l *Logger) WriterString(v ...any) {
	s := fmt.Sprintln(v...)
	l.logger.Printf("%s",
		s,
	)
}

func WriterString(l *Logger, v ...any) {
	l.WriterString(v...)
}
func (l *Logger) SetOutput(wc io.WriteCloser) {
	if l.wc != nil {
		l.wc.Close()
	}
	l.wc = wc
	var w io.Writer = wc
	l.logger.SetOutput(w)
}

func SetOutput(l *Logger, w io.WriteCloser) {
	l.SetOutput(w)
}

func GetWriteIO(pathName string) (io.WriteCloser, error) {
	return os.OpenFile(pathName, os.O_RDWR|os.O_CREATE|os.O_APPEND, os.FileMode(0666))
}
